package com.system.borrow.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.system.borrow.MyApplication;
import com.system.borrow.R;
import com.system.borrow.bean.TuiJian;
import com.system.borrow.widget.XCRoundRectImageView;

import java.util.ArrayList;
import java.util.List;

/**
 * ================================================
 * 作    者：LuCenly(落尘)
 * 版    本：1.0
 * 创建日期：2016/12/17 23:31
 * 描    述：TODO
 * ================================================
 */
public class LookListAdapter extends BaseAdapter{
    private List<TuiJian> list = new ArrayList<>();
    private Context context;
    private LayoutInflater inflater;

    public LookListAdapter(Context context, List<TuiJian> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_look_list,null);
            viewHolder.iv_img = (XCRoundRectImageView) convertView.findViewById(R.id.iv_img);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_tab = (TextView) convertView.findViewById(R.id.tv_tab);
            viewHolder.tv_amount = (TextView) convertView.findViewById(R.id.tv_amount);
            viewHolder.tv_monthRate = (TextView) convertView.findViewById(R.id.tv_monthRate);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        TuiJian tuiJian = list.get(position);
        MyApplication.imageLoader.displayImage(tuiJian.img,viewHolder.iv_img);
        viewHolder.tv_name.setText(tuiJian.name);
        viewHolder.tv_tab.setText(tuiJian.tag);
        viewHolder.tv_amount.setText(tuiJian.amount);
        viewHolder.tv_monthRate.setText(tuiJian.monthRate);
        return convertView;
    }

    public class ViewHolder {
        XCRoundRectImageView iv_img;
        TextView tv_name,tv_tab,tv_amount,tv_monthRate;

    }
}
